<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{padding:0;margin:0;}
        .box{
            width: 200px;
            height: 300px;
            margin:100px auto;
        }
        .content{
            float:left;
            width: 180px;
            background-color:pink;
        }
        .scroll{
            float:right;
            width: 20px;
            height: 300px;
            background-color:#ccc;
            position:relative;
        }
        .bar{
            width: 20px;
            height: 150px;
            border-radius:10px;
            background-color:darkred;
            position:absolute;
            left:0;
            top:0;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="content">

    </div>
    <div class="scroll">
        <div class="bar"></div>
    </div>
</div>
<script>
    var scroll=document.getElementsByClassName("scroll")[0];
    var box=document.getElementsByClassName("box")[0];
    var content=document.getElementsByClassName("content")[0];
    var bar=scroll.children[0];
    bar.onmousedown=function(ev){
        ev=ev||event;
        var y=ev.clientY-bar.offsetTop;
        document.onmousemove=function(ev){
            ev=ev||event;
            var yy=ev.clientY-y;
            (yy<0)&&(yy=0);
            (yy>scroll.offsetHeight-bar.offsetHeight)&&(yy=scroll.offsetHeight-bar.offsetHeight);
            bar.style.top=yy+"px";
//            content的高度/box的高度=当前bar的位置/总共可以滚动的距离
            var b=yy/(scroll.offsetHeight-bar.offsetHeight);
            content.style.height=box.offsetHeight*b+"px";
            document.onmouseup=function(){
                document.onmousemove=document.onmouseup=null;
            }
        }
    }
</script>
</body>
</html>